﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Xna.Framework;
using MonoGame.Framework.WindowsPhone;
using vservWindowsPhone;
using System.Net.NetworkInformation;
using System.Windows.Threading;

namespace VTGGoldMiner
{
    public partial class GamePage : PhoneApplicationPage
    {
        VservAdControl VAC = VservAdControl.Instance;

        // Constructor
        public GamePage()
        {
            InitializeComponent();
            if (NetworkInterface.GetIsNetworkAvailable()) { App.mang = true; }
            this.Loaded += AppView_Loaded; //Event for Showing Ad on Start
            VAC.SetRequestTimeOut(30);
            VAC.VservAdClosed += new EventHandler(VACCallback_OnVservAdClosing);
            VAC.VservAdError += new EventHandler(VACCallback_OnVservAdNetworkError);
            VAC.VservAdNoFill += new EventHandler(VACCallback_OnVservAdNoFill);
        }
        private void VACCallback_OnVservAdClosing(object sender, EventArgs e)
        {
            //MessageBox.Show("Ad Closed by user", "Interstitial Ad", MessageBoxButton.OK);
            ExecuteGame();
        }
        private void VACCallback_OnVservAdNetworkError(object sender, EventArgs e)
        {
            //MessageBox.Show("Data connection not available", "No Data", MessageBoxButton.OK);
            ExecuteGame();
        }
        private void VACCallback_OnVservAdNoFill(object sender, EventArgs e)
        {
            //MessageBox.Show("No Ad Available", "No Fill", MessageBoxButton.OK);
            ExecuteGame();
        }
        private void AppView_Loaded(object sender, RoutedEventArgs e)
        {
            VAC.DisplayAd("6fcbc5a9"/* Zone Id*/, adGrid/* Layout over which the Ad will be displayed*/);
        }
        private void ExecuteGame()
        {
            adGrid.Visibility = Visibility.Collapsed;
            this.SupportedOrientations = SupportedPageOrientation.Landscape;
            this.Orientation = PageOrientation.Landscape;
            App.game = XamlGame<DaoVang>.Create("", this);
        }
    }
}